/*
 * @Descripttion:
 * @Author: liuyu
 * @Date: 2023-12-04 15:44:23
 * @LastEditors: liuyu
 * @LastEditTime: 2023-12-04 15:44:23
 * @FilePath: /app/service/menu.js
 */
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class MenuService extends Service {
  // 获取详情信息
  async show(where) {
    const { app } = this;
    const res = await app.mysql.get('db1').get('menu', where);
    return res;
  }
  // 获取菜单
  async index(where = {}) {
    const { app } = this;
    console.log(where);
    const res = await app.mysql.get('db1').select('menu', {
      // auth menu授权部分排序也要同步调整
      orders: [[ 'order_num', 'acs' ]],
      where,
    });
    return res;
  }

  // 添加
  async create(data) {
    const { app } = this;
    data.create_time = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
    const res = await app.mysql.get('db1').insert('menu', data);
    return res;
  }
  // 修改
  async update(row, where) {
    row.update_time = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
    const res = await this.app.mysql.get('db1').update('menu', row, where);
    return res.affectedRows === 1;
  }
  // 删除
  async delete(id) {
    const res = await this.app.mysql.get('db1').delete('menu', { menu_id: id });
    return res;
  }
}
module.exports = MenuService;
